const bcrypt = require('bcrypt');
const {log} = require("debug");


// 生成一个随机的salt，通常建议使用genSaltSync(10)
const salt = bcrypt.genSaltSync(10);

const passwordCon = {
    //密码加密
    encryption(password) {
        // 使用bcrypt的hashSync方法将密码哈希化
        const hashedPassword = bcrypt.hashSync(password, salt);
        return hashedPassword
    },
    //判断密码是否相等
    decode(inputPassword, storedHashedPassword) {
        const isPasswordValid = bcrypt.compareSync(inputPassword, storedHashedPassword);
        return isPasswordValid
    }

}
// console.log(passwordCon.encryption(''))
// console.log(passwordCon.decode('', '$2b$10$9qIhZ6yQZyj0n.16/7W19er/fU/66dzaTlpH3Rz/E.uVIC2vhYgsu'))
module.exports = passwordCon






